/*
 *
 * @Date: 2022-06-15 20:44:10
 * @LastEditTime: 2022-06-19 20:30:15
 * @LastEditors:
 */
import {Component, OnInit} from '@angular/core';
import {PostItem} from '../../model/post-item';
import * as dayjs from 'dayjs';
import {Campus} from '../../enum/campus';
import {ApiPath} from '../../config/api-path';
import {HttpService} from '../../service/http.service';
import {ServerResponse} from '../../model/server-response';
import {Observable} from 'rxjs';
import {Router} from '@angular/router';

@Component({
  selector: 'app-help-container',
  templateUrl: './help-container.component.html',
  styleUrls: ['./help-container.component.scss'],
})
export class HelpContainerComponent implements OnInit {

  constructor(
    private HttpSrv: HttpService,
    private router: Router,
  ) {
  }

  ngOnInit() {
    this.initi();
  }

  HelpDataLs: PostItem[];

  initi() {
    this.HttpSrv.httpGet<PostItem[]>(ApiPath.request.forum.recentPosts)
      .subscribe(res => {
        if ('data' in res) {
          const ls: PostItem[] = res.data;
          ls.map(item => {
            item.headImgUrl = ApiPath.IMAGE_SERVER_PATH + item.headImgUrl;
            item.appointedTime = dayjs(item.appointedTime).format('MM-DD HH:mm');
            item.campus = Campus[item.campus];
          });
          this.HelpDataLs = ls;
          console.debug(this.HelpDataLs);
        }
      });
  }

  gotoDetails(postId: number) {
    this.router.navigate(['detail', postId]).then(r => r);
  }
  gotoCreate() {
    this.router.navigate(['/create',"help"]).then(r => r);
  }
}
